package com.gfm.story.controller;

import com.gfm.story.entity.base.PageBean;
import com.gfm.story.entity.base.ResultBean;
import com.gfm.story.entity.story.Chapter;
import com.gfm.story.service.story.ChapterService;
import com.gfm.story.util.ParamUtil;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @BelongsProject: story
 * @BelongsPackage: com.gfm.story.controller
 * @Author: Administrator
 * @CreateTime: 2019-06-04 16:44
 * @Description: 章节接口
 */
@RequestMapping("Chapter")
@Controller
public class ChapterController {
    @Resource
    private ChapterService chapterService;

    //根据书id获取章节
    @RequestMapping("/getChapterByBookId")
    public String getChapterByBookId(String bookId, HttpServletRequest request,PageBean pageBean,ModelMap modelMap) throws Exception {
        Map<String, Object> map = ParamUtil.getParameterMap(request);

        map.put("start", pageBean.getStart());
        map.put("pageSize", pageBean.getRows());
        if (bookId!=null){
            map.put("bookId", Long.parseLong(bookId));
            modelMap.put("ChapterList",chapterService.getChapterListByBookId(map,pageBean.getPage()));
            return "xs";
        }
        return "fl";
    }

    //获取最新更新的章节所属的图书信息
    @RequestMapping("getNewChapter")
    public String getNewChapter(HttpServletRequest request,int index,PageBean pageBean, ModelMap modelMap) throws Exception {
        Map<String, Object> map = ParamUtil.getParameterMap(request);
        map.put("start", pageBean.getStart());
        map.put("pageSize", pageBean.getRows());
        modelMap.put("bookList",chapterService.getChapterByNews(map,pageBean.getPage()));
        modelMap.put("index",index);
        return "ph";
    }


}
